package com.system.healthproject.model.admin.service.impl;

import com.system.healthproject.bean.PagesBean;
import com.system.healthproject.mapper.DiseaseLogMapper;
import com.system.healthproject.mapper.FrequencyMapper;
import com.system.healthproject.mapper.ReactionsMapper;
import com.system.healthproject.mapper.VisitRecordsMapper;
import com.system.healthproject.model.admin.paramsbean.FrequencyParams;
import com.system.healthproject.model.admin.paramsbean.ReactionsParams;
import com.system.healthproject.model.admin.paramsbean.VisitRecordsParams2;
import com.system.healthproject.model.admin.paramsbean.VisitRecordsShowParams;
import com.system.healthproject.model.admin.service.AdminVisitRecordsService;
import com.system.healthproject.pojo.DiseaseLog;
import com.system.healthproject.pojo.VisitRecords;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AdminVisitRecordsServiceImp implements AdminVisitRecordsService {

    @Autowired
    VisitRecordsMapper visitRecordsMapper;
    @Autowired
    DiseaseLogMapper diseaseLogMapper;
    @Autowired
    FrequencyMapper frequencyMapper;
    @Autowired
    ReactionsMapper reactionsMapper;

    @Override
    public boolean addVisitRecords(VisitRecordsParams2 addRecordParamss) {
        VisitRecords record = new VisitRecords();
        record.setHospitalName(addRecordParamss.getHospitalName());
        record.setDoctorName(addRecordParamss.getHospitalName());
        record.setVisitrecordstime(addRecordParamss.getVisitrecordstime());
        record.setVisitrecordsText(addRecordParamss.getVisitrecordsText());
        record.setVisitrecordsImgs(addRecordParamss.getVisitrecordsImgs());
        record.setVisitRecordsType(2);
        record.setPatientId(addRecordParamss.getPatientId());
        int insert = visitRecordsMapper.insert(record);
        return insert==1;
    }

    @Override
    public PagesBean<VisitRecordsShowParams> getVisitRecordsList(int page, int size, int userId) {
        PagesBean<VisitRecordsShowParams> visitRecordsShowParamsPagesBean = new PagesBean<>();

        List<VisitRecordsShowParams> visitRecordsShowParams =
                visitRecordsMapper.selectList((page-1)*size, size, userId);
        int totalByUserId = visitRecordsMapper.getTotalByUserId(userId);
        visitRecordsShowParamsPagesBean.setData(visitRecordsShowParams);
        visitRecordsShowParamsPagesBean.setNowsPage(page);
        visitRecordsShowParamsPagesBean.setPageSize(size);
        visitRecordsShowParamsPagesBean.setDataCount(totalByUserId);
        return visitRecordsShowParamsPagesBean;
    }

    @Override
    public VisitRecords getVisitRecordsInfo(Integer visitRecordId) {
        VisitRecords visitRecords = visitRecordsMapper.selectByPrimaryKey(visitRecordId);

        return visitRecords;
    }

    @Override
    public PagesBean<Map<String, Object>> getDiseaseLogList(int page, int size, int userId) {
        PagesBean<Map<String, Object>> mapPagesBean = new PagesBean<>();

        List<Map<String, Object>> diseaseLogList =
                diseaseLogMapper.getDiseaseLogList((page - 1) * size, size, userId);
        int total = diseaseLogMapper.getTotal(userId);
        mapPagesBean.setNowsPage(page);
        mapPagesBean.setPageSize(size);
        mapPagesBean.setData(diseaseLogList);
        mapPagesBean.setDataCount(total);
        return mapPagesBean;
    }

    @Override
    public DiseaseLog getDiseaseLogById(int id) {
        DiseaseLog diseaseLog = diseaseLogMapper.selectByPrimaryKey(id);

        return diseaseLog;
    }

    @Override
    public List<FrequencyParams> getFrequencyList(int type, int userId) {
        List<FrequencyParams> diseaseLogListByDay=null;
        if(type==1){
             diseaseLogListByDay = frequencyMapper.getDiseaseLogListByDay(userId);
        }else if(type==2){
            diseaseLogListByDay = frequencyMapper.getDiseaseLogListByWeek(userId);
        }else if(type==3){
            diseaseLogListByDay = frequencyMapper.getDiseaseLogListByMonth(userId);
        }
        return diseaseLogListByDay;
    }

    @Override
    public List<ReactionsParams> getReactions(int type, int userId) {
        List<ReactionsParams> reactionsByWeek=null;
        if(type==2){
             reactionsByWeek = reactionsMapper.getReactionsByWeek(userId);
        }else if(type==3){
             reactionsByWeek = reactionsMapper.getReactionsByMonth(userId);
        }else if(type==1){
            reactionsByWeek = reactionsMapper.getReactionsByDay(userId);
        }
        return reactionsByWeek;
    }


}
